* Article title: "Who is Credible? Government Popularity and the Catalytic Effect of IMF Lending"

* Journal: Comparative Political Studies

* Author: Sujeong Shim, University of Zurich

* This Stata do-file is for use with the accompanying datset saved as "Main dataset.dta".

*Stata version: 16.1

use "C:\Users\sujeo\OneDrive\바탕 화면\RESEARCH\DRAFTS\2020 publication version\4차 submission\RnR\Main dataset.dta", replace

######################
# Preparing the data #
######################



#########################################################
# Lagging and differencing variables for ECM estimation #
#########################################################


#Lagging variables by one period: 

sort ccode year 
by ccode: gen lag_popularity = popularity[_n-1]
by ccode: gen lag_imf=imf[_n-1]
by ccode: gen lag_IMF_cond=IMF_cond[_n-1]
by ccode: gen lag_logIMFloan=logIMFloan[_n-1]

by ccode: gen lag_default=default[_n-1]
by ccode: gen lag_polity2=polity2[_n-1]
by ccode: gen lag_veto=veto[_n-1]
by ccode: gen lag_maj=maj[_n-1]
by ccode: gen lag_budget_bal=budget_bal[_n-1]
by ccode: gen lag_us10yrbond=us10yrbond[_n-1]


by ccode: gen lag_UNvoting=UNvoting[_n-1]
by ccode: gen lag_right_gov=right_gov[_n-1]
by ccode: gen lag_growth=growth[_n-1]
by ccode: gen lag_curr=curr[_n-1]
by ccode: gen lag_totalreserve=totalreserve[_n-1]
by ccode: gen lag_logGDPPC=logGDPPC[_n-1]

by ccode: gen lag_participation=participation[_n-1]
by ccode: gen lag_ln_liquidity=ln_liquidity[_n-1]

by ccode: gen lag_QPCavrg=QPCsTOT_avrg[_n-1]
by ccode: gen lag_SPCavrg=SPCsTOT_avrg[_n-1]
by ccode: gen lag_QPCSPCavrg=QPCSPC_TOT_avrg[_n-1]

by ccode: gen lag_QPC=QPCsTOT[_n-1]
by ccode: gen lag_SPC=SPCsTOT[_n-1]
by ccode: gen lag_QPCSPC=QPCSPC_TOT[_n-1]




#Differencing variables

gen spread_dif=spread_avg_an - lag_spread
gen popularity_dif=popularity-lag_popularity
gen imf_dif=imf-lag_imf
gen IMF_cond_dif=IMF_cond-lag_IMF_cond
gen logIMFloan_dif=logIMFloan-lag_logIMFloan
gen election_dif=election-lag_election
gen default_dif=default-lag_default
gen right_gov_dif=right_gov-lag_right_gov
gen growth_dif=growth-lag_growth
gen polity2_dif=polity2-lag_polity2
gen curr_dif=curr-lag_curr 
gen logGDPPC_dif=logGDPPC-lag_logGDPPC
gen UNvoting_dif=UNvoting-lag_UNvoting
gen participation_dif=participation-lag_participation
gen QPCSPC_dif=QPCSPC_TOT-lag_QPCSPC
gen veto_dif=veto-lag_veto
gen maj_dif= maj-lag_maj
gen budget_bal_dif=budget_bal-lag_budget_bal



###########################################################
# Generating key independent variables #
###########################################################

gen lag_imf_popularity_dif=lag_imf*popularity_dif
gen lag_imf_lag_popularity=lag_imf*lag_popularity
gen lag_QPCSPC_lag_popularity=lag_QPCSPC*lag_popularity
gen lag_QPCSPC_popularity_dif=lag_QPCSPC*popularity_dif



###########################################################
# Generating instrumental variables #
###########################################################

gen IV1=UNvoting*ln_liquidity
gen IV2=QPCSPC_TOT_avrg*ln_liquidity
gen IV3=participation*ln_liquidity


by ccode: gen lag_IV1=IV1[_n-1]
by ccode: gen lag_IV2=IV2[_n-1]
by ccode: gen lag_IV3=IV3[_n-1]

gen lag_IV1_lag_popularity=lag_IV1*lag_popularity
gen lag_IV1_popularity_dif=lag_IV1*popularity_dif
gen lag_IV2_popularity_dif=lag_IV2*popularity_dif
gen lag_IV2_lag_popularity=lag_IV2*lag_popularity
gen lag_IV3_popularity_dif=lag_IV3*popularity_dif
gen lag_IV3_lag_popularity=lag_IV3*lag_popularity



###########################################################
# Results in Tables 1, A4 and A5 #
###########################################################
eststo clear


#IMF programs as binary variable#
eststo: xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_polity2 polity2_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif i.ccode i.year lag_participation (lag_imf lag_imf_popularity_dif lag_imf_lag_popularity = lag_IV3 lag_IV1 lag_IV3_popularity_dif lag_IV3_lag_popularity lag_IV1_popularity_dif lag_IV1_lag_popularity), r first


# IMF programs as conditionality #

eststo: xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif  lag_logIMFloan  logIMFloan_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_polity2 polity2_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif i.ccode i.year lag_participation (lag_imf lag_QPCSPC lag_QPCSPC_lag_popularity lag_QPCSPC_popularity_dif = lag_IV3 lag_IV1 lag_IV2 lag_IV2_lag_popularity lag_IV2_popularity_dif), r first

esttab using main_results.rtf, replace  star(* .10 ** .05 *** .01) se



###########################################################
# Matching analysis # Table A6 ############################
###########################################################


#Creating a binary treatment variable
gen popular=1 if popularity>60
replace popular=0 if popularity<60
by ccode: gen lag_popular=popular[_n-1]
by ccode: gen popular_dif=popular-lag_popular
by ccode: gen lag_imf_lag_popular=lag_imf*lag_popular
by ccode: gen lag_imf_popular_dif=lag_imf*popular_dif
by ccode: gen lag_IV1_lag_popular=lag_IV1*lag_popular
by ccode: gen lag_IV1_popular_dif=lag_IV1*popular_dif
by ccode: gen lag_IV3_lag_popular=lag_IV3*lag_popular
by ccode: gen lag_IV3_popular_dif=lag_IV3*popular_dif



### Running regression on matched sample #####

psmatch2 lag_popular lag_growth lag_curr lag_default lag_budget_bal lag_logGDPPC lag_polity2 lag_election lag_veto lag_UNvoting lag_right_gov us10yrbond, out(spread_dif) logit ties n(4) 

eststo clear

eststo: xi: ivreg2 spread_dif lag_spread lag_popular popular_dif  lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_polity2 polity2_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif i.ccode i.year lag_participation (lag_imf lag_imf_popular_dif lag_imf_lag_popular = lag_IV3 lag_IV1 lag_IV3_popular_dif lag_IV3_lag_popular lag_IV1_popular_dif lag_IV1_lag_popular) [pweight=_weight],r

esttab using matching0721.rtf, replace  star(* .10 ** .05 *** .01) se



########################################
# Regime type analysis (Figure A6) #####
########################################

eststo clear
gen democracy=1 if polity2>5
replace democracy=0 if polity2<6
gen lag_imf_popularity_dif_democracy=lag_imf_popularity_dif*democracy
gen lag_imf_lag_popularity_democracy=lag_imf_lag_popularity*democracy
gen lag_IV1_popularity_dif_democracy=lag_IV1_popularity_dif*democracy
gen lag_IV1_lag_popularity_democracy=lag_IV1_lag_popularity*democracy
gen lag_IV1_democracy=lag_IV1*democracy
gen lag_IV3_popularity_dif_democracy=lag_IV3_popularity_dif*democracy
gen lag_IV3_lag_popularity_democracy=lag_IV3_lag_popularity*democracy
gen lag_IV3_democracy=lag_IV3*democracy
gen lag_popularity_democracy=lag_popularity*democracy
gen approavl_dif_democracy=popularity_dif*democracy
gen lag_imf_democracy=lag_imf*democracy


probit imf c.lag_UNvoting##c.lag_ln_liquidity c.lag_participation##c.lag_ln_liquidity lag_curr lag_growth lag_veto lag_right_gov lag_election
predict xb2, xb
predict phat2, pr

gen bias=normalden(xb2)/phat2
by ccode: gen lag_bias=bias[_n-1]

xtreg spread_dif lag_spread c.lag_imf##c.popularity_dif##democracy c.lag_imf##c.lag_popularity##democracy lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif i.ccode i.year lag_participation lag_bias, fe

margins, dydx(popularity_dif) at(lag_imf==1 lag_imf==0 democracy==1 democracy==0)

marginsplot, plot2opts(lpattern("--")) title ("Marginal effect of government popularity" "on sovereign bond spreads") xtitle("IMF participation")




####################################################################
# Presidential vs. Parliamentary systemm (Table A7)#################
####################################################################

gen presidential=1 if system=="Presidential"
replace presidential=0 if system=="Parliamentary"

eststo clear

eststo: xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif lag_logIMFloan lag_IMF_cond lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto lag_polity2 lag_right_gov lag_curr curr_dif lag_UNvoting i.ccode i.year lag_participation  (lag_imf lag_imf_popularity_dif lag_imf_lag_popularity = lag_IV3 lag_IV1 lag_IV3_popularity_dif lag_IV3_lag_popularity lag_IV1_popularity_dif lag_IV1_lag_popularity) if presidential==1, r 

eststo: xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif lag_logIMFloan lag_IMF_cond lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto lag_polity2 lag_right_gov lag_curr curr_dif lag_UNvoting i.ccode i.year lag_participation  (lag_imf lag_imf_popularity_dif lag_imf_lag_popularity = lag_IV3 lag_IV1 lag_IV3_popularity_dif lag_IV3_lag_popularity lag_IV1_popularity_dif lag_IV1_lag_popularity) if presidential==0, r 

esttab using pres_par.rtf, se replace star(* .10 ** .05 *** .01)




####################################################################
# Testing alternative mechanism on government turnover (Table A8)###
####################################################################


eststo clear
eststo: xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_logGDPPC logGDPPC_dif lag_election lag_veto veto_dif lag_polity2 polity2_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif i.ccode i.year lag_participation (lag_imf lag_imf_popularity_dif lag_imf_lag_popularity = lag_IV3 lag_IV1 lag_IV3_popularity_dif lag_IV3_lag_popularity lag_IV1_popularity_dif lag_IV1_lag_popularity) if yrsoffc>1, r


eststo: xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_logGDPPC logGDPPC_dif lag_election lag_veto veto_dif lag_polity2 polity2_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif yrsoffc i.ccode i.year lag_participation (lag_imf lag_imf_popularity_dif lag_imf_lag_popularity = lag_IV3 lag_IV1 lag_IV3_popularity_dif lag_IV3_lag_popularity lag_IV1_popularity_dif lag_IV1_lag_popularity), r

esttab using altern1.rtf, se replace star(* .10 ** .05 *** .01)


###############################################################################
# Testing alternative mechanism on majority government control (Table A9)######
###############################################################################

gen lag_imf_lag_maj=lag_imf*lag_maj
gen lag_imf_maj_dif=lag_imf*maj_dif
gen lag_IV3_maj_dif= lag_IV3*maj_dif
gen lag_IV3_lag_maj= lag_IV3*lag_maj
gen lag_IV1_maj_dif=lag_IV1*maj_dif
gen lag_IV1_lag_maj=lag_IV1*lag_maj


#Replacing popularity ratings with gov't seat share####
eststo clear
eststo: xi: ivreg2 spread_dif lag_spread lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_maj maj_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif i.ccode lag_ln_liquidity lag_participation (lag_imf lag_imf_maj_dif lag_imf_lag_maj = lag_IV3 lag_IV1 lag_IV3_maj_dif lag_IV3_lag_maj lag_IV1_maj_dif lag_IV1_lag_maj), r first


#controlling for govt seat share####
eststo: xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_maj maj_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif i.ccode lag_ln_liquidity lag_participation (lag_imf lag_imf_popularity_dif lag_imf_lag_popularity = lag_IV3 lag_IV1 lag_IV3_popularity_dif lag_IV3_lag_popularity lag_IV1_popularity_dif lag_IV1_lag_popularity), r first

esttab using altern2.rtf, star(* .10 ** .05 *** .01) se





##############################################################
# Additional robustness checks (Tables A10, A11, and A12) ####
##############################################################


by ccode: gen lag_cbi=cbi[_n-1]
by ccode: gen cbi_dif=cbi-lag_cbi
by ccode: gen lag_gini=gini[_n-1]
by ccode: gen gini_dif = gini-lag_gini
by ccode: gen lag_reserve=totalreserve[_n-1]
by ccode: gen reserve_dif=totalreserve- l.totalreserve
by ccode: gen lag_loglt_govdebt=loglt_gov_debt[_n-1]
by ccode: gen logltgovdebt_dif=loglt_gov_debt-lag_loglt_govdebt

eststo clear

#Table A10 model1#
xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_polity2 polity2_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif lag_gini gini_dif  i.ccode i.year lag_participation (lag_imf lag_imf_popularity_dif lag_imf_lag_popularity = lag_IV3 lag_IV1 lag_IV3_popularity_dif lag_IV3_lag_popularity lag_IV1_popularity_dif lag_IV1_lag_popularity), r 

#Table A10 model2#
xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_polity2 polity2_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif lag_cbi cbi_dif i.ccode i.year lag_participation (lag_imf lag_imf_popularity_dif lag_imf_lag_popularity = lag_IV3 lag_IV1 lag_IV3_popularity_dif lag_IV3_lag_popularity lag_IV1_popularity_dif lag_IV1_lag_popularity), r 

#Table A11 model1#

xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_polity2 polity2_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif lag_reserve reserve_dif i.ccode i.year lag_participation (lag_imf lag_imf_popularity_dif lag_imf_lag_popularity = lag_IV3 lag_IV1 lag_IV3_popularity_dif lag_IV3_lag_popularity lag_IV1_popularity_dif lag_IV1_lag_popularity), r

#Table A11 model2#
xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif lag_logIMFloan logIMFloan_dif lag_IMF_cond IMF_cond_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_polity2 polity2_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif lag_loglt_govdebt logltgovdebt_dif i.ccode i.year lag_participation (lag_imf lag_imf_popularity_dif lag_imf_lag_popularity = lag_IV3 lag_IV1 lag_IV3_popularity_dif lag_IV3_lag_popularity lag_IV1_popularity_dif lag_IV1_lag_popularity), r


#Table A12#
gen lag_QPC_lag_popularity=lag_QPC*lag_popularity
gen lag_SPC_lag_popularity=lag_SPC*lag_popularity
gen lag_QPC_popularity_dif=lag_QPC*popularity_dif
gen lag_SPC_popularity_dif=lag_SPC*popularity_dif
gen IV4=QPCsTOT_avrg*ln_liquidity
gen IV5=SPCsTOT_avrg*ln_liquidity
by ccode: gen lag_IV4=IV4[_n-1]
by ccode: gen lag_IV5=IV5[_n-1]
gen lag_IV4_popularity_dif=lag_IV4*popularity_dif
gen lag_IV4_lag_popularity=lag_IV4*lag_popularity
gen lag_IV5_popularity_dif=lag_IV5*popularity_dif
gen lag_IV5_lag_popularity=lag_IV5*lag_popularity


xi: ivreg2 spread_dif lag_spread lag_popularity popularity_dif lag_logIMFloan logIMFloan_dif lag_default lag_budget_bal budget_bal_dif lag_growth growth_dif lag_election lag_veto veto_dif lag_polity2 polity2_dif lag_right_gov lag_curr curr_dif lag_UNvoting UNvoting_dif i.ccode i.year lag_participation (lag_QPC lag_QPC_popularity_dif lag_QPC_lag_popularity lag_SPC lag_SPC_popularity_dif lag_SPC_lag_popularity= lag_IV4 lag_IV4_popularity_dif lag_IV4_lag_popularity lag_IV5 lag_IV5_popularity_dif lag_IV5_lag_popularity), r 




